<?php

declare(strict_types=1);

namespace App\Controller\Kpi;

use Hyperf\HttpServer\Annotation\AutoController;
use Hyperf\Validation\Annotation\Scene;
use App\Service\Version as VersionService;
use App\Request\VersionRequest;

#[AutoController]
class VersionController extends AbstractController
{
    // 版本列表
    public function list()
    {
        $map = [];
        $type = $this->request->input('type', 'android');
        $map[] = ['type', '=', $type];
        $result = (new VersionService())->list($map);
        return $this->returnSuccess($result, '成功');
    }
    // 添加版本
    #[Scene(scene: 'add', argument: 'request')]
    public function add_version(VersionRequest $request)
    {
        $params = $request->validated();
        $result = (new VersionService())->addVersion($params);
        return $this->returnSuccess($result, '保存成功');
    }
    
    // 编辑版本
    #[Scene(scene: 'edit', argument: 'request')]
    public function edit_version(VersionRequest $request)
    {
        $params = $request->validated();
        $result = (new VersionService())->editVersion($params['id'],$params);
        return $this->returnSuccess($result, '保存成功');
    }

    // 删除版本
    public function delete_version()
    {
        $id = $this->request->input('id', 0);
        if (!$id)
            return $this->returnError('请求参数错误');
        $data = (new VersionService())->deleteVersion($id);
        return $this->returnSuccess($data, '删除成功');
    }
}
